// pages/personal/view-card/view-card.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:'',
    desc:'',
    id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var cardId = options.cardId;
    // cardId = 'd53e38875302472a8fc39b0c67310dc0';
    console.log('卡片ID为:' + cardId);
    //获取页面传递的卡片id,去获取卡片基本信息
    var url = app.globalData.serverAddress + '/api/personal/view/' + cardId + '?_t=' + new Date().getTime();
    app.httpPost(url, '').then((res) => {
      if(res.data.flag){
        var imgUrl = res.data.picUrl;
        var name = res.data.info.userName;
        var desc = res.data.info.personalDesc;
        var id = res.data.info.id;
        if (imgUrl){
          that.setData({
            picUrl: imgUrl,
            name: name,
            desc:desc,
            id:id
          });
        }else{
          that.setData({
            picUrl:'../../../images/2.jpg',
            name: name,
            desc: desc,
            id:id
          });
        }
      }else{

      }
   
    }).catch((errMsg) => {
      console.log(errMsg); //错误提示信息
      wx.showModal({
        content: '网络异常',
        showCancel: false,
      })
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
    console.log('点击分享');
    if(res.from ==='button'){
      console.log(res.target,res);
    }

    if (res.from === 'menu') {
      console.log(res);
    }

    return {
      title: '我的名片',
      path: '/pages/personal/view-card/view-card?cardId=' + this.data.id, 
      success: function (res) {
        // 转发成功
        console.log(res);
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }


  }
})